package com.scujcc.require;


import java.util.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RequireDto {
	@Autowired
	private RequireRepository repo;
	public List<Require> getAll(){
		List<Require> result = null;
		result = repo.findAll();
		return result;
	}
	
	public Require getRequire(String id) {
		Require result = new Require();
		if(null!=id) {
			if(repo.findById(id).isPresent())
			{
				result=repo.findById(id).get();
			}
		}
		
		return result;
	}
	
	public boolean deleteRequire(String id) {
		boolean result = true;
		try {
		repo.deleteById(id);
		}catch(Exception e) {
			result = false;
		}
		return result;
	}
	
	
	public Require createRequire(Require c) {
		return repo.save(c);
	}
	public Require updateRequire(Require r) {
		Require updateAfter = null;
		updateAfter = getRequire(r.getId());
		if(r.getMessage()!=null) {
			updateAfter.setMessage(r.getMessage());
		}
		return repo.save(updateAfter);
	}
	public List<Require> searchByDesc(String desc){
		return repo.findByDescLike(desc);
	}
}